<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Yaf_Plugin_Abstract class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="yaf-loader.setlibrarypath.html">« Yaf_Loader::setLibraryPath</a></li>
      <li style="float: right;"><a href="yaf-plugin-abstract.dispatchloopshutdown.html">Yaf_Plugin_Abstract::dispatchLoopShutdown »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.yaf.html">Yaf</a></li>
    <li>The Yaf_Plugin_Abstract class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.yaf-plugin-abstract" class="reference">

 <h1 class="title">The Yaf_Plugin_Abstract class</h1>
 

 <div class="partintro"><p class="verinfo">(Yaf &gt;=1.0.0)</p>


  <div class="section" id="yaf-plugin-abstract.intro">
   <h2 class="title">简介</h2>
   <p class="para">
     Plugins 可以让你轻松地定制和扩展框架
   </p>
   <p class="para">
       插件(Plugins)是一个类。
       基于组件定义的类会有所变化 -- 你可能需要去实现这些接口。
       但实际上，该插件(Plugin)本身就是一个类。
   </p>
   <p class="para">
     一个插件(plugin)会被<span class="methodname"><a href="yaf-dispatcher.registerplugin.html" class="methodname">Yaf_Dispatcher::registerPlugin()</a></span>加载到Yaf框架中，
     在框架注册(registerd)后，插件(plugin)类中定义方法将会在恰当的时间被该接口执行。
   </p>
  </div>


 <div class="section">
  <h2 class="title">范例</h2>
  <div class="example" id="example-3911">
   <p><strong>示例 #1 Plugin example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;bootstrap&nbsp;class&nbsp;should&nbsp;be&nbsp;defined&nbsp;under&nbsp;./application/Bootstrap.php&nbsp;*/<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Bootstrap&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Yaf_Bootstrap_Abstract&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">_initPlugin</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Dispatcher&nbsp;$dispatcher</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;register&nbsp;a&nbsp;plugin&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$dispatcher</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">registerPlugin</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">TestPlugin</span><span style="color: #007700">());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;plugin&nbsp;class&nbsp;should&nbsp;be&nbsp;placed&nbsp;under&nbsp;./application/plugins/&nbsp;*/<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">TestPlugin&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Yaf_Plugin_Abstract&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">routerStartup</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;在路由之前执行,这个钩子里，你可以做url重写等功能&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"routerStartup"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">routerShutdown</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;路由完成后，在这个钩子里，你可以做登陆检测等功能*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"routerShutdown"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">dispatchLoopStartup</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"dispatchLoopStartup"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">preDispatch</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"preDispatch"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">postDispatch</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"postDispatch"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">dispatchLoopShutdown</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract&nbsp;$request</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Yaf_Response_Abstract&nbsp;$response</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;final&nbsp;hoook<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in&nbsp;this&nbsp;hook&nbsp;user&nbsp;can&nbsp;do&nbsp;loging&nbsp;or&nbsp;implement&nbsp;layout&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #DD0000">"dispatchLoopShutdown"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;Class&nbsp;</span><span style="color: #0000BB">IndexController&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Yaf_Controller_Abstract&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">indexAction</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//prevent&nbsp;rendering<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$config&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"application"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"directory"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/application/"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$app&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$app</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bootstrap</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">run</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
string(13) &quot;routerStartup&quot;
string(14) &quot;routerShutdown&quot;
string(19) &quot;dispatchLoopStartup&quot;
string(11) &quot;preDispatch&quot;
string(12) &quot;postDispatch&quot;
string(20) &quot;dispatchLoopShutdown&quot;
</pre></div>
   </div>
  </div>
 </div>


  <div class="section" id="yaf-plugin-abstract.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Yaf_Plugin_Abstract</strong>
     </span>
     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.dispatchloopshutdown.html" class="methodname">dispatchLoopShutdown</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.dispatchloopstartup.html" class="methodname">dispatchLoopStartup</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.postdispatch.html" class="methodname">postDispatch</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.predispatch.html" class="methodname">preDispatch</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.preresponse.html" class="methodname">preResponse</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.routershutdown.html" class="methodname">routerShutdown</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-plugin-abstract.routerstartup.html" class="methodname">routerStartup</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.html" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>, <span class="methodparam"><span class="type"><a href="class.yaf-response-abstract.html" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span> <code class="parameter">$response</code></span>): <span class="type"><span class="type void">void</span></span></div>

   }</div>


  </div>

 </div>

 



















































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="yaf-plugin-abstract.dispatchloopshutdown.html">Yaf_Plugin_Abstract::dispatchLoopShutdown</a> — The dispatchLoopShutdown purpose</li><li><a href="yaf-plugin-abstract.dispatchloopstartup.html">Yaf_Plugin_Abstract::dispatchLoopStartup</a> — The dispatchLoopStartup purpose</li><li><a href="yaf-plugin-abstract.postdispatch.html">Yaf_Plugin_Abstract::postDispatch</a> — The postDispatch purpose</li><li><a href="yaf-plugin-abstract.predispatch.html">Yaf_Plugin_Abstract::preDispatch</a> — The preDispatch purpose</li><li><a href="yaf-plugin-abstract.preresponse.html">Yaf_Plugin_Abstract::preResponse</a> — The preResponse purpose</li><li><a href="yaf-plugin-abstract.routershutdown.html">Yaf_Plugin_Abstract::routerShutdown</a> — The routerShutdown purpose</li><li><a href="yaf-plugin-abstract.routerstartup.html">Yaf_Plugin_Abstract::routerStartup</a> — RouterStartup hook</li></ul>
</div>
</div></div></body></html>